package cn.cloud.mqtt2redis.service;

import cn.cloud.mqtt2redis.controller.JsonProbe;
import cn.cloud.mqtt2redis.controller.JsonProtocol;
import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MqttService {

    @Autowired
    private JsonProtocol jsonProtocol;
    @Autowired
    private JsonProbe jsonProbe;

    public void handle_message(String topic, JSONObject message){
        //System.out.println(topic);
        //System.out.println(message);
        if(topic.contains("Discovery/Response")){                 //设备发现
            this.jsonProtocol.parse_device_discovery(message);
        }else if(topic.contains("Register/Response")) {
            this.jsonProtocol.parse_device_register(message);
        }else if(topic.contains("Probe/Version/Response/")){               //侦测probe文件版本号
            this.jsonProtocol.parse_model_probe_change(topic,message);
        }else if(topic.contains("Probe/Query/Response/")){        //获取probe文件
            this.jsonProbe.parse_model_probe(topic,message);
        }else if(topic.contains("Query/Response/")){             //查询
            this.jsonProtocol.parse_query_response(topic,message);
        }
    }
}
